package com.wwwarehouse.carddesk.fragment.teamfragment.checkdownclassfragemnt;

import android.os.Bundle;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.carddesk.bean.teambean.DelayTaskBean;
import com.wwwarehouse.carddesk.constant.CardDeskConstant;
import com.wwwarehouse.common.fragment.CommonBasePagerFragment;
import com.wwwarehouse.common.tools.LogUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @创建者 chenchao.
 * @创建时间 2017/11/13 13:35
 * @描述 ${TODO}
 */

public class DelayTaskFragment extends CommonBasePagerFragment {


    private String mUserId;

    @Override
    public void setTitle() {
        if (peekFragment() instanceof DelayTaskFragment) {
            mActivity.setTitle(R.string.teamdesk_delay_detail);
        }

    }

    @Override
    public void requestDatas() {
        super.requestDatas();
        hideConfirmButton();
        if (getArguments() != null) {
            mUserId = getArguments().getString("userId");
        }
        requestHttp();

    }

    private void requestHttp() {
        Map<String, Object> delayTaskMap = new HashMap<>();
        delayTaskMap.put("opUserId", mUserId);
        delayTaskMap.put("page", 1);
        delayTaskMap.put("size", 9);
        loadData(CardDeskConstant.GET_DELAY_DATA, delayTaskMap, 0);
    }

    @Override
    public void onRefreshListener() {
        requestHttp();
    }

    @Override
    public void onLoadSuccess(String data, int what) {
        if (0 == what) {
            DelayTaskBean delayTaskBean = JSON.parseObject(data, DelayTaskBean.class);
            int total = delayTaskBean.getTotal();
            ArrayList<DelayTaskBean.ListBean> list = (ArrayList<DelayTaskBean.ListBean>) delayTaskBean.getList();
            Bundle delayTaskToChildBundle = new Bundle();
            delayTaskToChildBundle.putString("userId", mUserId);
            try {
                setData(total, 9, "com.wwwarehouse.carddesk.fragment.teamfragment.checkdownclassfragemnt.DelayTaskFragmentChild", delayTaskToChildBundle, list);
            } catch (Exception e) {
                LogUtils.showLog(e.toString());
            }

        }
    }

    @Override
    public void onLoadError(String errorInfo) {

    }

    @Override
    public void onDownPull() {
        //        super.onDownPull();
    }
}
